package com.example.administrator.q1;

import android.content.Context;
import android.content.Intent;
import android.graphics.pdf.PdfDocument;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

public class slideActivity extends AppCompatActivity {

    Button button_Enter;
    ViewPager viewPager;
    int[] my_Image = new int[]{R.mipmap.p1, R.mipmap.p2, R.mipmap.p3, R.mipmap.p4};
    List<ImageView> my_List = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slide);

        button_Enter = (Button)findViewById(R.id.button_Enter);
        viewPager = (ViewPager) findViewById(R.id.ViewPager);

        // viewPager.setPageTransformer(true,new ZoomOutPagetransformer());
        // 为viewPager设置adapter
        viewPager.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return my_Image.length;
            }

            @Override
            public boolean isViewFromObject(View view, Object o) {
                return view == o;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(my_List.get(position));
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                //代码创建ImageView控件
                ImageView imageView = new ImageView(slideActivity.this);
                //ImageView赋值图片
                imageView.setImageResource(my_Image[position]);
                //ImageView赋值动画效果
                imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                //容器添加ImageView
                container.addView(imageView);
                //临时集合添加ImageView
                my_List.add(imageView);
                return imageView;
            }
        });

        // 跳转页面
        button_Enter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(slideActivity.this, MainActivity.class);
                startActivity(intent);
                // Exit
                finish();
            }
        });

    }


}
